package com.yswee.framework.data.parser;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import com.google.gson.Gson;

public class BaseGsonParser<T> extends BaseJsonParser<T> {
	
	protected Gson mGson;
	
	public BaseGsonParser() {
		mGson = new Gson();
	}

	@Override
	public T parseData(String json) {
		mReponseData = json;
		Class<T> cls = getTClassType();
		return mGson.fromJson(json, cls);
	}
	
	@SuppressWarnings("unchecked")
	protected Class<T> getTClassType() {
		Type genType = getClass().getGenericSuperclass();  
        Type[] params = ((ParameterizedType) genType).getActualTypeArguments();  
		return (Class<T>) params[0]; 
	}

}
